<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<meta name="description" content="Mailbox with some customizations as described in docs" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<%@ include file="/include/person_include.jsp"%>
 <body>
    <div id="main">
        <div id="bal">
            <p>
                <span>到账银行卡</span>
                <c:if test="${empty bank }">
                <span id="addToBank" onclick="addToBank()"><b style="font-size:22px;">+</b>添加银行卡</span>
                </c:if>
                <c:if test="${not empty bank }">
                <span>${bank}（${bankCode}）</span>
                </c:if>
            </p>
            <!--<span><i>2017-03-20</i>&nbsp;&nbsp;到&nbsp;&nbsp;<i>2017-04-20</i></span>-->
            <p>总营收</p>
            <div>
                <!-- 				￥&nbsp;&nbsp; -->
                <i>￥${waitWithdrawMoney }</i>
            </div>
        </div>
       
        <div class="part_two">
            <p>提现扣除</p>
       		<c:if test="${not empty serviceFee }">
            <span>微信支付宝提现手续费：${serviceFee }元</span>
            </c:if>
            <span>银联转账手续费 <i>2</i>元/笔<i></i></span>
            <p>
                	最终到账
                <i>￥${trueAccount }</i>
            </p>
            <div>
                <input type="text" name="code"  id="code" />
                <input  name="userId" type="hidden"  value="${pd.userId }"/>
               <input   name="token" type="hidden"  value="${pd.token }"/>
               <input   name="businessId" type="hidden"  value="${pd.businessId }"/>
                <button id="getCodeBtn">获取验证码</button>
            </div>
            <button id="submitBtn">提现</button>
        </div>
    </div>
 <div class="back">
    <button onclick="back()">返回</button>
</div>
<div class="layer" id="layer" style="display:none">
    <div class="msg">
        <div class="person-msg">
            <div><span>持卡人姓名：</span><input type="text"  name="bankName"  value="${bankName }"/></div>
            <div><span>卡号：</span><input type="text"  name="bankCard"  value="${bankCode }"/></div>
            <div><span>开户行：</span><input type="text" name="bank"  value="${ bank}"/></div>
            <div><span>开户分行：</span><input type="text"  name="bankBranch" value="${bankBranch }" /></div>
             <input  name="userId" type="hidden"  value="${pd.userId }"/>
               <input   name="token" type="hidden"  value="${pd.token }"/>
               <input   name="businessId" type="hidden"  value="${pd.businessId }"/>
        </div>
        <div class="btn">
            <button onclick="personAddBank();">确定</button>
        </div>
    </div>
</div>
<script type="text/javascript">
var bank="${bank}";
function addToBank(){
	$("#layer").show();
}
function personAddBank(){
	var bankName=$.trim($("input[name=bankName]").val());
	var bankCode=$.trim($("input[name=bankCard]").val());
	var bank1=$.trim($("input[name=bank]").val());
	var bankBranch=$.trim($("input[name=bankBranch]").val());
	if(bankName==""){
		alert("持卡人姓名不能为空");
		return
	}
	if(bankBranch==""){
		alert("开户支行不能为空");
		return
	}
	if(bankCode==""){
		alert("银行卡号不能为空");
		return
	}
	if(bank1==""){
		alert("开户行不能为空");
		return
	}
	
	 $.get(rootpath + '/apiH5/addBank',{
		 userId:'${pd.userId}',
		 token:'${pd.token}',
		 businessId:'${pd.businessId}',
		 bankName:bankName,
		 bankCard:bankCode,
		 bank:bank1,
		 bankBranch:bankBranch
	 }, function(data, status) {
         if (data.code==0) {
        	 alert("添加成功");
        	 $("#layer").hide();
        	 bank=bank1;
        	  $("#addToBank").html(bank+"("+bankCode+")");
         }  
     });
}
function back(){
	window.history.back(-1);
}
    $(function() {
        var balance =parseFloat( '${trueAccount }');
        /* if (  balance<=0) {
            $('#submitBtn').parent().remove();
        } */
        $('#submitBtn').on('click', function() {
        	if (  balance<=0) {
            	layer.msg('余额不足,不能提现');
            	return; 
            }
        	var code=$("#code").val();
        	if(code==''){
        		layer.msg('请输入验证码');
            	return; 
        	}
        	
        	 $.get(rootpath + '/apiH5/withdraw.do?userId=${pd.userId}&token=${pd.token}&businessId=${pd.businessId}&code='+code, function(data, status) {
        		 if(data.code==0){
        			 layer.msg("提现成功");
        			  setTimeout(function() {
        				  back();
        	            }, 1000)
        		 }else{
        			 layer.msg(data.msg);
        		 }
        	 });
        });

        $('#getCodeBtn').on('click', function() {
            var getCodeBtn = $(this);
            if (  balance<=0) {
            	layer.msg('余额不足,不能提现');
            	return; 
            }
            var bankCode=bank;
            if(bankCode==""){
            	layer.msg('请先绑定银行卡');
            	return;
            }
            $(getCodeBtn).attr("disabled", true);
             
            $.get(rootpath + '/apiH5/sendCode.do?userId=${pd.userId}&token=${pd.token}&businessId=${pd.businessId}', function(data, status) {
                if (data.code==0) {
                        settime(getCodeBtn);
                        layer.msg('验证码已发送');
                }else {
                	 $(getCodeBtn).attr("disabled", false);
                        layer.msg('验证码发送失败,'+data.msg)
                }
            });
            return false;
        });

        var countdown = 60;
        function settime(obj) {
            if (countdown == 0) {
            	$(getCodeBtn).attr("disabled", false);
                $(getCodeBtn).html("获取验证码");
                countdown = 60;
                return;
            } else {
                $(obj).attr("disabled", true);
                $(obj).html("重新发送(" + countdown + ")");
                countdown--;
            }
            setTimeout(function() {
                settime(obj)
            }, 1000)
        }
 
    });
</script>
</body>

  
</html>